package com.example.zhongxinjinqiao.myapplication;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.GestureDetector;
import android.view.MotionEvent;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;

import com.androidnetworking.error.ANError;
import com.example.zhongxinjinqiao.myapplication.util.Net;

import org.json.JSONObject;

import java.util.HashMap;

public class MainActivity extends AppCompatActivity {
    GestureDetector gesture;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        gesture = new GestureDetector(new GestureDetector.SimpleOnGestureListener(){
            @Override
            public boolean onSingleTapConfirmed(MotionEvent e) {
                hiddenKeyboard();
                return super.onSingleTapConfirmed(e);
            }
        });

        if(getSupportActionBar () != null) {
            getSupportActionBar ().hide ();

        }
    }


    @Override
    protected void onStart() {
        super.onStart();
        setTitle("主页");
    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {

        return gesture.onTouchEvent(event);
    }

    public  void onclickLogin(View view) {
       EditText edit = findViewById(R.id.editText2);
       edit.setText("点击了");
       Intent intent = new Intent(this,HomeActivity.class);
       Bundle bundle = new Bundle ();
       this.startActivity(intent);


        HashMap<String,String> parameters = new HashMap<String, String> ( );
        parameters.put ( "cityname","成都" );
        parameters.put ( "key","5584239b25132fbf817cd73c7ae38770" );
        Net.get ("http://v.juhe.cn/weather/index",parameters, new Net.State() {
            @Override
            public void failed(ANError error) {
                System.out.print ( error );

            }

            @Override
            public void success(JSONObject response) {
                System.out.print ( response );
            }
        });

    }

    public void onclickRegister(View btn) {
        finish();
    }

    private  void hiddenKeyboard() {

        InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
        if (imm != null) {
            imm.hideSoftInputFromWindow(getWindow().getDecorView().getWindowToken(), 0);
        }
    }

}


